package com.itheima.controller;


import com.github.pagehelper.PageInfo;
import com.itheima.domain.Student;
import com.itheima.service.StudentService;
import com.itheima.service.StudentServiceImpl;
import org.junit.Test;

import java.util.List;

public class StudentTest {


    private StudentService studentService = new StudentServiceImpl();

    @Test
    public void testFindAll(){
        List<Student> list = studentService.findAll();
        for (Student student : list) {
            System.out.println(student);
        }
    }

    /*
     *分页查询学生信息
     */
    @Test
    public void testFindPage(){
        PageInfo<Student> students = studentService.findByPage(1,3);

            System.out.println(students);
        System.out.println("============");
        System.out.println(students.getList());

    }

    @Test
    public void testAdd(){
        Student stu = new Student(13,"溜溜",22);
        int result = studentService.addStu(stu);
        System.out.println(result);

    }

    @Test
    public void testUpdate(){
        Student stu = new Student(3, "行喊", 33);
        int result = studentService.updateStu(stu);
        System.out.println(result);
    }

    @Test
    public void testDelete(){
        int result = studentService.deleteStu(12);
        System.out.println(result);
    }


   /*动态sql
    * 动态sql根据条件查询
    */
    @Test
    public void testFindByCondition(){
        Student stu = new Student();
       stu.setId(2);
//        stu.setName("ss");
        stu.setAge(24);
        List<Student> list = studentService.findByCondition(stu);
        for (Student student : list) {
            System.out.println(student);
        }
    }



    /*根据多个id查询
    */
    @Test
    public void testFindByIds(){
        List<Student> list = studentService.findByIds(1, 3, 5);
        for (Student student : list) {
            System.out.println(student);
        }
    }

   /*动态sql修改学生信息
    */
    @Test
    public void testupdateStu2(){
        Student stu = new Student(1,"礼物", 11);
        int result = studentService.updateStu2(stu);
        System.out.println(result);
    }
}
